package com.peanut.common;


import com.peanut.em.ResultEnum;

/**
 * ajax返回值 : 如果分页就把page扔进去 ， 如果是根据id查询 实体类扔进去 如果是集合 把list扔进去
 */
public class Result<T> {
    private Integer code;
    private String message;
    private String title;
    private Integer count;
    private T data;

    public static Result fallback() {
        Result r = new Result();
        r.setCode(ResultEnum.FEIGN_FALLBACK.getCode()); //自定义成功返回码
        r.setMessage(ResultEnum.FEIGN_FALLBACK.getMessage());
        return r;
    }

    public static Result NO() {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode()); //自定义成功返回码
        result.setMessage(ResultEnum.SUCCESS.getMessage());
        return result;
    }


    public String getTitle() {
        return title;
    }


    public static Result OK() {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode()); //自定义成功返回码
        result.setMessage(ResultEnum.SUCCESS.getMessage());
        return result;
    }

    public static Result ERROR() {
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getCode()); //自定义成功返回码
        result.setMessage(ResultEnum.ERROR.getMessage());
        return result;
    }

    public static Result LOGIN_ERROR() {
        Result result = new Result();
        result.setCode(ResultEnum.LOGIN_ERROR.getCode()); //自定义成功返回码
        result.setMessage(ResultEnum.LOGIN_ERROR.getMessage());
        return result;
    }

    public static Result R(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMessage(resultEnum.getMessage());
        return result;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }


    public Result setTitle(String title) {
        this.title = title;
        return this;
    }

    public Result setCount(Integer count) {
        this.count = count;
        return this;
    }

    public Integer getCount() {
        return count;
    }

}
